package com.owc.common.enums;

import com.owc.common.rule.BackPwdCacheKeyRule;
import com.owc.common.rule.IRule;
import com.owc.common.rule.LoginCacheKeyRule;
import com.owc.common.rule.RegisterCacheKeyRule;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author xiaom
 * @Date 2019/12/2 14:49
 * @Version 1.0.0
 * @Description <>
 **/
@Getter
public enum SendCodeEnum {
    REGISTER(1,"注册类型",new RegisterCacheKeyRule()),
    LOGIN(2,"登录",new LoginCacheKeyRule()),
    BACKPASSWORD(3,"找回密码",new BackPwdCacheKeyRule());

    private Integer type;

    private String desc;

    private IRule<String,String> rule;

    SendCodeEnum(Integer type, String desc,IRule<String,String> rule) {
        this.type = type;
        this.desc = desc;
        this.rule = rule;
    }

    /**
     * Find client enum by client type.
     * @param type type
     * @return Client enum example.
     */
    public static Optional<SendCodeEnum> match(Integer type) {
        return Arrays.stream(SendCodeEnum.values())
                .filter(t -> t.getType().equals(type))
                .findFirst();
    }
}
